
import * as PIXI from 'pixi.js';
import Image from 'components/image';
import RuleBtn from './ruleBtn';
// import Text from 'components/text';
import {findGameApp} from 'common/utils';
const { Container } = PIXI;

export default class BeginGame {
  constructor({parent, onRuleClick = () => {}, ...props}) {

    const { top, beginBtn, notice } = props;

    this.parent = parent;
    this.container = new Container();

    this._renderBtn(beginBtn);

    this.ruleBtn = new RuleBtn({parent: this, ...notice});
    this.ruleBtn.container.interactive = true;
    this.ruleBtn.container.on('tap', () => {
      onRuleClick();
    });
    this.container.addChild(this.ruleBtn.container);

    this.container.y = top;
    this.container.x = (findGameApp(this).app.screen.width - this.container.width) / 2;
  }

  _renderBtn = (data) => {
    const { src, width, height, top } = data;

    let btn = new Image({
      src, width, height, left: 0, top, isAdapt: false
    });

    btn.interactive = true;
    btn.on('tap', () => {
      findGameApp(this).enterScene('game');
    });

    this.container.addChild(btn);
  };

}
